/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs.module.datalogging.model;

import org.openmrs.BaseOpenmrsData;
import org.openmrs.Person;
import org.openmrs.api.context.Context;
import org.openmrs.module.datalogging.configuration.Variable;

import java.util.Date;

/**
 *
 */
public class LogEntry extends BaseOpenmrsData {
	
	private Integer logEntryId;
	
	private LogEvent logEvent;
	
	private Variable variable;
	
	private Person person;
	
	private String valueText;
	
	private Date valueDatetime;
	
	private Double valueNumeric;
	
	/**
	 * Return the value of the logId
	 * 
	 * @return the logId
	 */
	public Integer getLogEntryId() {
		return logEntryId;
	}
	
	/**
	 * Set the logId with the logId value
	 * 
	 * @param logEntryId the logId to set
	 */
	public void setLogEntryId(Integer logEntryId) {
		this.logEntryId = logEntryId;
	}
	
	/**
	 * Return the value of the logEvent
	 * 
	 * @return the logEvent
	 */
	public LogEvent getLogEvent() {
		return logEvent;
	}
	
	/**
	 * Set the logEvent with the logEvent value
	 * 
	 * @param logEvent the logEvent to set
	 */
	public void setLogEvent(LogEvent logEvent) {
		this.logEvent = logEvent;
	}
	
	/**
	 * Return the value of the variable
	 * 
	 * @return the variable
	 */
	public Variable getVariable() {
		return variable;
	}
	
	/**
	 * Set the variable with the variable value
	 * 
	 * @param variable the variable to set
	 */
	public void setVariable(Variable variable) {
		this.variable = variable;
	}
	
	/**
	 * Return the value of the person
	 * 
	 * @return the person
	 */
	public Person getPerson() {
		return person;
	}
	
	/**
	 * Set the person with the person value
	 * 
	 * @param person the person to set
	 */
	public void setPerson(Person person) {
		this.person = person;
	}
	
	/**
	 * Return the value of the valueText
	 * 
	 * @return the valueText
	 */
	public String getValueText() {
		return valueText;
	}
	
	/**
	 * Set the valueText with the valueText value
	 * 
	 * @param valueText the valueText to set
	 */
	public void setValueText(String valueText) {
		this.valueText = valueText;
	}
	
	/**
	 * Return the value of the valueDatetime
	 * 
	 * @return the valueDatetime
	 */
	public Date getValueDatetime() {
		return valueDatetime;
	}
	
	/**
	 * Set the valueDatetime with the valueDatetime value
	 * 
	 * @param valueDatetime the valueDatetime to set
	 */
	public void setValueDatetime(Date valueDatetime) {
		this.valueDatetime = valueDatetime;
	}
	
	/**
	 * Return the value of the valueNumeric
	 * 
	 * @return the valueNumeric
	 */
	public Double getValueNumeric() {
		return valueNumeric;
	}
	
	/**
	 * Set the valueNumeric with the valueNumeric value
	 * 
	 * @param valueNumeric the valueNumeric to set
	 */
	public void setValueNumeric(Double valueNumeric) {
		this.valueNumeric = valueNumeric;
	}
	
	/**
	 * @see org.openmrs.OpenmrsObject#getId()
	 */
	@Override
	public Integer getId() {
		return getLogEntryId();
	}
	
	/**
	 * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
	 */
	@Override
	public void setId(Integer id) {
		setLogEntryId(id);
	}
	
	/**
	 * @return String representation of the log entry
	 */
	public String getValue() {
		if (getValueNumeric() != null)
			return String.valueOf(getValueNumeric());
		else if (getValueDatetime() != null)
			return Context.getDateFormat().format(getValueDatetime());
		else
			return getValueText();
	}
}
